import type {
  ArticleListParams,
  ArticleListRes,
  ChannelRes,
  LoginRes,
  PublishArticleParams,
  UserInfoRes,
} from '@/types'
import { request } from '@/utils/reuqest'

// 登录接口封装
export const loginAPI = (data: FormData) => {
  // 返回 Promise
  return request<LoginRes>('v1_0/authorizations', 'post', data)
}

export const getUserInfoAPI = () => {
  return request<UserInfoRes>('/v1_0/user/profile', 'get')
}
export const uploadImageAPI = (file: FormData) => {
  return request<{ url: string }>('/v1_0/upload', 'POST', file)
}

export const getChannelsAPI = () => {
  return request<ChannelRes>('/v1_0/channels')
}
export const getArticleListAPI = (params: ArticleListParams) => {
  return request<ArticleListRes>('/v1_0/mp/articles', 'GET', params)
}
export const delArticleAPI = (id: number) => {
  return request(`/v1_0/mp/articles/${id}`, 'DELETE')
}

// 文章发布
export const pubArticleAPI = (draft: boolean, data: PublishArticleParams) => {
  return request(`/v1_0/mp/articles/`, 'POST', data)
}

// 获取文章详情
export const getArticleDetailAPI = (id: string) => {
  return request<PublishArticleParams>(`/v1_0/mp/articles/${id}`)
}

// 修改文章
export const updateArticleAPI = (id: string, draft: boolean, data: PublishArticleParams) => {
  return request(`/v1_0/mp/articles/${id}`, 'PUT', data)
}
